<?php
namespace app\common\model;

use think\Db;
use think\Model;

class Comment extends Base
{

	/**
	 * [getNormalCommentsCountByCondition 通过条件获取评论数量]
	 * @param  array   $param [description]
	 * @param  integer $form  [description]
	 * @param  integer $size  [description]
	 * @return [type]         [description]
	 */
	public function getNormalCommentsCountByCondition($param = []){
		// status = 1 自行完成
		$count = Db::table('ent_comment')
		->alias(['ent_comment'=>'a' , 'ent_user'=>'b'])
		->join('ent_user', 'a.user_id = b.id AND a.status = 1 AND a.news_id = '.$param['news_id'])
		->count();
		return $count;
    }

    /**
     * [getNormalCommentsCondition 通过条件获取列表数据]
     * @param  array   $condition [description]
     * @param  integer $form      [description]
     * @param  integer $size      [description]
     * @return [type]             [description]
     */
    public function getNormalCommentsCondition($param, $form = 0, $size = 5){
		$result = Db::table('ent_comment')
		->alias(['ent_comment'=>'a' , 'ent_user'=>'b'])
		->join('ent_user', 'a.user_id = b.id AND a.news_id = '.$param['news_id'])
		->limit($form,$size)
		->order(['a.id'=>'desc'])
		->select();

		return $result;
    }


    /**
     * [getCountByCondition 获取评论总说]
     * @param  integer $param  [description]
     * @return [type]         [description]
     */
    public function getCountByCondition($param = []){
		return $this->where($param)
		->count();
    }

    /**
     * 获取列表页
     */
    public function getListsByCondition($param, $from = 0, $size = 5){
    	return $this->where($param)
    	->field('*')
    	->limit($from,$size)
    	->order(['id'=>'desc'])
    	->select();
    }

}
